

package com.yungu.swift.order.utils;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Zerrion
 * @version 1.0
 * @description 线程池操作处理类
 * @date 2017/10/26 18:12
 */
public class ThreadExecutorUtils {
    /**
     * 线程池操作处理
     */
    private static final ExecutorService POOL = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),
            100, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024),
            new ThreadFactoryBuilder().build(), new ThreadPoolExecutor.AbortPolicy());

    /**
     * 执行线程
     *
     * @param runnable
     */
    public static final void execute(Runnable runnable) {
        POOL.execute(runnable);
    }

    /**
     * 关闭线程池
     */
    public static final void shutdown() {
        POOL.shutdown();
    }
}
